package com.zdb.datastructures.stack;

public class Calculator {

    public static void main(String[] args) {
        String str = "";
        int index = 0;

        ArrayStackCalculator numStack = new ArrayStackCalculator(10);
        ArrayStackCalculator operStack = new ArrayStackCalculator(10);
    }

}

class ArrayStackCalculator {

    private int maxeSize;
    private int[] arr;
    private  int top = -1;

    public ArrayStackCalculator(int maxeSize) {
        this.maxeSize = maxeSize;
        arr = new int[maxeSize];
    }

    public boolean isFull() {
        return top == maxeSize -1;
    }

    public void push(int i) {
        if(isFull()) {
            throw new RuntimeException("栈已经满了");
        }

        top++;
        arr[top] = i;
    }

    public boolean isEmpty() {
        return top == -1;
    }

    public int pop() {
        if(isEmpty()) {
            throw new RuntimeException("栈为空");
        }

        int v = arr[top];
        top--;
        return v;
    }

    public void print() {
        if(isEmpty())  {
            System.out.println("栈为空");
            return;
        }
        for(int i=top; i>-1; i--) {
            System.out.print(arr[i] + " -> ");
        }
        System.out.println();
    }

    private int getPriority(int oper) {
        if('*' == oper || '/' == oper) {
            return 1;
        } else if('+' == oper || '-' == oper) {
            return  0;
        } else  {
            throw new RuntimeException("不支持此运算符 " + (char)oper);
        }
    }

    public boolean isOper(int oper) {
        return oper == '+' || oper == '-' || oper == '*' || oper == '/';
    }

    public int cal(int x, int y, int oper) {
        switch (oper) {
        case '-':
            return x - y;
        case '+':
            return x + y;
        case '*':
            return x * y;
        case '/':
            return x / y;
        default:
            throw new RuntimeException("不支持该操作符：" + (char)oper);
        }
    }


}


